﻿// Test_AVPacket.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include "pch.h"
#include <tchar.h>
#include <windows.h>
#include "../../../../NetEngine_Windows/NetEngine_SourceCode/XyRyNet_CommHdr.h"
#include "../../../../NetEngine_Windows/NetEngine_SourceCode/NetEngine_AvCoder/NetEngine_AVPacket/AVPacket_Define.h"
#include "../../../../NetEngine_Windows/NetEngine_SourceCode/NetEngine_AvCoder/NetEngine_AVPacket/AVPacket_Error.h"
#pragma comment(lib,"../../../../NetEngine_Windows/NetEngine_SourceCode/Debug/NetEngine_AVPacket.lib")

void __stdcall AVPacket_Pack_CBNotify(XNETHANDLE xhNet, int nCvtType, int nCvtFrame, double dlTime, LPVOID lParam)
{
	printf("AVPacket_UNPack_CBNotify:%d %d %lf\n", nCvtType, nCvtFrame, dlTime);
}

int AVPacket_Test_FileConvert()
{
	XNETHANDLE xhAVFile = 0;
	double nTotalAVTime = 0;
	LPCTSTR lpszSrcFile = "E:\\netengineapp\\NetEngine_WINApps\\Debug\\480p.264";
	LPCTSTR lpszDstFile = "E:\\netengineapp\\NetEngine_WINApps\\Debug\\480p.flv";
	
	if (!AVPacket_FileUNPack_Init(&xhAVFile, AVPacket_Pack_CBNotify))
	{
		printf("AVPacket_FileUNPack_Init:%lX\n", AVPacket_GetLastError());
		return -1;
	}
	if (!AVPacket_FileConvert_Input(xhAVFile, lpszSrcFile, &nTotalAVTime))
	{
		printf("AVPacket_FileUNPack_Input:%lX\n", AVPacket_GetLastError());
		return -1;
	}
	printf("AVTime:%lf\n", nTotalAVTime);
	if (!AVPacket_FileConvert_Output(xhAVFile, lpszDstFile))
	{
		printf("AVPacket_FileUNPack_Output:%lX\n", AVPacket_GetLastError());
		return -1;
	}
	if (!AVPacket_FileConvert_Start(xhAVFile))
	{
		printf("AVPacket_FileUNPack_Start:%lX\n", AVPacket_GetLastError());
		return -1;
	}
	while (1)
	{
		BOOL bIsRun = FALSE;
		if (AVPacket_FileConvert_GetStatus(xhAVFile, &bIsRun))
		{
			if (!bIsRun)
			{
				break;
			}
		}
		Sleep(1000);
	}
	return AVPacket_FileConvert_Stop(xhAVFile);
}

int AVPacket_Test_FilePacket()
{
	XNETHANDLE xhAVFile = 0;
	LPCTSTR lpszVideoFile = "E:\\netengineapp\\NetEngine_WINApps\\Debug\\480p.264";
	LPCTSTR lpszAudioFile = "E:\\netengineapp\\NetEngine_WINApps\\Debug\\test.aac";
	LPCTSTR lpszDstFile = "E:\\netengineapp\\NetEngine_WINApps\\Debug\\480p.flv";

	if (!AVPacket_FilePacket_Init(&xhAVFile, AVPacket_Pack_CBNotify))
	{
		printf("AVPacket_FileUNPack_Init:%lX\n", AVPacket_GetLastError());
		return -1;
	}
	if (!AVPacket_FilePacket_Input(xhAVFile, lpszVideoFile, lpszAudioFile))
	{
		printf("AVPacket_FileUNPack_Input:%lX\n", AVPacket_GetLastError());
		return -1;
	}
	if (!AVPacket_FilePacket_Output(xhAVFile, lpszDstFile))
	{
		printf("AVPacket_FileUNPack_Output:%lX\n", AVPacket_GetLastError());
		return -1;
	}
	if (!AVPacket_FilePacket_Start(xhAVFile))
	{
		printf("AVPacket_FileUNPack_Start:%lX\n", AVPacket_GetLastError());
		return -1;
	}

	while (1)
	{
		BOOL bIsRun = FALSE;
		if (AVPacket_FilePacket_GetStatus(xhAVFile, &bIsRun))
		{
			if (!bIsRun)
			{
				break;
			}
		}
		Sleep(1000);
	}
	return AVPacket_FilePacket_Stop(xhAVFile);
}

int AVPacket_Test_UNPacket()
{
	XNETHANDLE xhAVFile = 0;
	BOOL bAudio = FALSE;
	BOOL bVideo = FALSE;

	LPCTSTR lpszVideoFile = "E:\\netengineapp\\NetEngine_WINApps\\Debug\\480p.264";
	LPCTSTR lpszAudioFile = "E:\\netengineapp\\NetEngine_WINApps\\Debug\\test.aac";
	LPCTSTR lpszSrcFile = "E:\\netengineapp\\NetEngine_WINApps\\Debug\\480p.flv";

	if (!AVPacket_FileUNPack_Init(&xhAVFile, AVPacket_Pack_CBNotify))
	{
		printf("AVPacket_FileUNPack_Init:%lX\n", AVPacket_GetLastError());
		return -1;
	}
	double dlAVTime = 0;
	if (!AVPacket_FileUNPack_Input(xhAVFile, lpszSrcFile, &bVideo, &bAudio, &dlAVTime))
	{
		printf("AVPacket_FileUNPack_Input:%lX\n", AVPacket_GetLastError());
		return -1;
	}
	printf("AVTime:%lf\n", dlAVTime);
	if (!AVPacket_FileUNPack_Output(xhAVFile, lpszVideoFile, lpszAudioFile))
	{
		printf("AVPacket_FileUNPack_Output:%lX\n", AVPacket_GetLastError());
		return -1;
	}
	if (!AVPacket_FileUNPack_Start(xhAVFile))
	{
		printf("AVPacket_FileUNPack_Start:%lX\n", AVPacket_GetLastError());
		return -1;
	}
	while (1)
	{
		BOOL bIsRun = FALSE;
		if (AVPacket_FileUNPack_GetStatus(xhAVFile, &bIsRun))
		{
			if (!bIsRun)
			{
				break;
			}
		}
		Sleep(1000);
	}
	return AVPacket_FilePacket_Stop(xhAVFile);
}
int main()
{
	//AVPacket_Test_UNPacket();
	AVPacket_Test_FilePacket();
	return 1;
}